package Leason;

import java.util.Scanner;


public class Test1 {
    public static class TreeNode {
        char val;
        TreeNode left;
        TreeNode right;

        public TreeNode(char val) {
            this.val = val;
        }
    }
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (scan.hasNextLine()) { // 注意 while 处理多个 case
            String str = scan.nextLine();
            TreeNode root = createTree(str);
            //中序遍历
            inorder(root);
        }
    }
    //题目给出一个先序序列 编写程序得出中序序列
    public static int i = 0;
    private static TreeNode createTree(String str) {
        TreeNode root = null;
        char ch = str.charAt(i);
        if(ch != '#') {
            root = new TreeNode(ch);
            i++;
            root.left = createTree(str);
            root.right = createTree(str);
        }else {
            i++;
        }
        return root;
    }

    private static void inorder(TreeNode  root) {
        if(root == null) {
            return;
        }
        inorder(root.left);
        System.out.print(root.val+" ");
        inorder(root.right);
    }
}
